<?php

/**

redis 重新命名的方式

*/


namespace app\common\lib;


use app\common\api\BayouSmsApi;
use app\common\api\SmsSingleSender;
use app\common\api\SmsSenderUtil;
use app\common\lib\Predis;
use app\common\lib\Rekey;


class Task{
	
	/**
     * 异步发送 验证码
     * @param $data
     * @param $serv swoole server对象
    */
	public function sendSms($data ,$serv=null){
		
		try{
			$this->sendByMobile($data['mobile'],361678,'陕西今朝',array($data['code'],5));
			if($data['code'] != '888888'){
				return false;
			}
			Predis::getInstance()->set(Rekey::smsKey($data['mobile']),$data['code']);
			
		}catch(\Exception $e){
			return false;
		}
	}
	
	
	/**
	*
	*/
	public function  pushLive($data,$serv){
		$clients = Predis::getInstance()->sMembers("live_game_key");
		
		foreach($clients as $fd) {
            $serv->push($fd, json_encode($data));
        }
	}
	
	
	
	/**
	*  腾讯短信服务接口
	*  $mobile   发送信息的电话号码
	*  $templateId  短信模版的 id号
	*  $smsSign  签名
	*  $option   模版参数匹配
	*/
	private function sendByMobile($mobile,$templateId=208087,$smsSign='陕西今朝',$option=array()){
		//1400开头
		$appid = 1400150463; 
		// 短信应用SDK AppKey
		$appkey = "b4e60ac3d2d3b0c4954c74364c481b4b";
		
		$ssender = new SmsSingleSender($appid, $appkey);
		try {
			
			$result = $ssender->sendWithParam("86",$mobile , $templateId, $option, $smsSign, "", "");  // 签名参数未提供或者为空时，会使用默认签名发送短信
			return $result;
			
		} catch(\Exception $e) {
			return false;
		}
	}
	
	
	
	
	
}